/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;
import java.io.Serializable;
import helper.*;
import model.board.*;
import model.players.*;

public class Game implements Serializable
{
//ATTRIBUTE ====================================================================
    //QUEUE PLAYERS YG SEBENERNYA BUKAN QUEUE___________________________________
    public Players Q;
    public int urutan_current_plyr = 1;

    public Player current_plyr()
    {
        return (Q.player[urutan_current_plyr]);
    }
    //BOARDS____________________________________________________________________
    public Kotak[] B;
    public Kotak current_kotak()
    {
        return (B[current_plyr().getPosisi()]);
    }

    //perihal file XML yang berisi Lokasi Pariwisata. Cieee perihal..
    private String fileXML = new String ("lokasi_pariwisata.xml");
    public String getFileXML()
    {
        return fileXML;
    }
    public void setFileXML(String _fileXML)
    {
        fileXML = new String (_fileXML);
    }

    //STATES____________________________________________________________________
    
    public   boolean skip_next = false;

    public boolean skip_next()
    {
        return skip_next;
    }
    
    public int coba_keluar_penjara = 0;
    //__________________________________________________________________________

//CONSTRUCTOR ====================================================================
    public Game()
    //digunakan entah untuk apa.
    {
        //Assign Board
        B = new Kotak[33];
        AssignBoard(fileXML);
        //Assign Players
        Q = new Players(4);
        for (int i = 1; i<=4; i++)
        {
            Q.add(new Player (i, "P-".concat(Integer.toString(i)), "images"+Integer.toString(i-1)+".gif",true ));
        }

        //mono dirty
        Q.player[2].setHuman(false);
        Q.player[4].setHuman(false);

        //lgs assign LP lah
        B[2].BeliAset(Q.player[1]);
        B[3].BeliAset(Q.player[2]);
        B[5].BeliAset(Q.player[1]);
        B[6].BeliAset(Q.player[2]);
        B[7].BeliAset(Q.player[1]);
        B[8].BeliAset(Q.player[2]);
        B[10].BeliAset(Q.player[1]);
        B[11].BeliAset(Q.player[2]);
        B[13].BeliAset(Q.player[1]);
        B[16].BeliAset(Q.player[2]);
    }

    public Game (Kotak[] _B, Players _Q)
    //digunakan bila pemain melakukan new game
    {
        //assign Board
        B = _B; // baca dari fileXML
        //assign Players
        Q = _Q;
    }

     public Game (Players _Q)
    //digunakan bila pemain melakukan new game
    {
        //assign Board
        B = new Kotak[33];
        AssignBoard(fileXML);
        //assign players
        Q = _Q;
    }

    public Game (Game _G)
    //digunakan bila pemain melakukan load game
    {
        //assign board
        B = _G.B;
        //assign players
        Q = _G.Q;
        //assign states
        urutan_current_plyr = _G.urutan_current_plyr;
        coba_keluar_penjara = _G.coba_keluar_penjara;
    }

    public Game LoadGame(String filename)
    {
        return (Game)helper.IOSavedGame.Load(filename);
    }

//METHOD
    //mengassign B dengan data2 dari file lokasipariwisata
    public void AssignBoard(String filename)
    {
        if (XMLReader.parseToArrLP(filename, 18))//ini bagian ngebaca dari fileXML, emang tipe balikkannya dibikin boolean
        {
            for (int i = 1; i<=32; i++)
            {
                B[i] = new Kotak();
                B[i] = B[i].newKotak(i);
            }
        }
    }


    public static void main (String args[])
    {
        Game game = new Game(new Kotak[32], new Players(4));
        helper.IOSavedGame.Simpan("LISAAA", game);
    }
}